﻿
@{
    ViewData["Title"] = "BuildLogDetails";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<nav aria-label="breadcrumb">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="/Projects/Index">Projects</a></li>
        <li class="breadcrumb-item"><a href="/Projects/Details?projectid=@ViewBag.BuildLog.ProjectId">Project Details</a></li>
        <li class="breadcrumb-item active" aria-current="page">Build Details</li>
    </ol>
</nav>

<div class="container">
    <div class="row">
        <div class="col">
            <span>@ViewBag.BuildLog.ProjectName</span>--
            <span>@ViewBag.BuildLog.Id</span>--
            <span>@ViewBag.BuildLog.BuildNum</span>--
            <span id="BuildState"></span>--
            <span>@ViewBag.BuildLog.BuildTime</span>
        </div>
    </div>
</div>

<div class="container">
    <div class="row">
        <div class="col">
            <div style="width:100%;height:500px">
                <textarea id="OutContent" style="height:500px; width:100%;" readonly></textarea>
            </div>
            <br />
            <div style="width:100%;" class="inputdiv">
                <div class="row">
                    <div class="col-10">
                        <input type="text" class="form-control" id="InputContent">
                    </div>
                    <div class="col-2">
                        <button type="button" class="btn btn-primary" onclick="sendInput(escape('@ViewBag.BuildLog.Id'))">Send</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


@section Scripts{

    <script src="~/js/signalr/dist/webworker/signalr.js"></script>
    <script>
        $(function () {

            var connection = new signalR.HubConnectionBuilder().withUrl("/iohub").build();

            connection.on("ReceiveBuildMessage", function (iokey, message) {
                //console.log(iokey);
                //console.log(message);

                $('#OutContent').val($('#OutContent').val()+'\n' + message);
                //文本框滚动到底部
                $('#OutContent').scrollTop($('#OutContent')[0].scrollHeight);

            });
            connection.start();
        })
    </script>
    <script>
        function loadBuildLog(buildlogid) {
            $.get("/Projects/GetBuildlog", { buildlogid: buildlogid }, function (res) {
                if (res.code == 1) {
                    $('#BuildState').val(res.data.buildState)
                    $('#OutContent').val(+'\n'+res.data.outContent)
                    //文本框滚动到底部
                    $('#OutContent').scrollTop($('#OutContent')[0].scrollHeight);

                    //if (res.data.buildState == '0') {
                    //    $('.inputdiv').show();

                    //    setTimeout(function () {
                    //        loadBuildLog(res.data.id);
                    //    }, 5000);
                    //}
                    //else {
                    //    $('.inputdiv').hide();
                    //}
                }
            });
        }
        function sendInput(buildlogid) {
            $.post("/Projects/SendBuildInput", { buildlogid: buildlogid, content: $('#InputContent').val() }, function (res) {
                if (res.code == 1) {
                    $('#InputContent').val('')
                }
            });
        }

        loadBuildLog(escape('@ViewBag.BuildLog.Id'));

    </script>

}
